package ui.home.column3.chat

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.onPointerEvent
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import state.ApplicationWindowsState
import state.WindowType
import theme.EasyChatTheme
import ui.compose.RectIconButton
import ui.home.HomeViewModel


/**
 * @author wei kunJie
 * @date 2024/3/12 14:55:36
 * 聊天框标题行
 */
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun ChatTitleRow(
    title: MutableState<String>,
    easyChatTheme: MutableState<EasyChatTheme>,
    applicationWindowsState: ApplicationWindowsState,
    homeViewModel: HomeViewModel
) {
    val isPointerEnter = remember { mutableStateOf(-1) }
    Row(modifier = Modifier.padding(start = 24.dp, bottom = 12.dp, end = 24.dp)) {
        Text(
            text = title.value, style = TextStyle(
                color = Color.Black,
                fontSize = 18.5.sp
            )
        )
        Spacer(Modifier.weight(1f))
        RectIconButton(
            onClick = {
                homeViewModel.openPhone()
            },
            modifier = Modifier.size(30.dp)
                .clip(RoundedCornerShape(8.dp))
                .background(color = Color.Transparent)
                .onPointerEvent(PointerEventType.Enter) { isPointerEnter.value = 1 }
                .onPointerEvent(PointerEventType.Exit) { isPointerEnter.value = -1 },
        ) {
            Icon(
                painter = painterResource("icon/ic_phone.svg"),
                contentDescription = "语音通话",
                modifier = Modifier.size(20.dp),
                tint = if (isPointerEnter.value == 1) easyChatTheme.value.mainColor else Color.Black
            )
        }

    }
}